package edu.ustb.efws.pipeline.collect.handler;

import edu.ustb.efws.EfwsProperties;
import edu.ustb.efws.base.domain.Position;
import edu.ustb.efws.base.domain.User;
import edu.ustb.efws.base.service.PositionService;
import edu.ustb.efws.base.service.SmsService;
import edu.ustb.efws.base.service.UserService;
import edu.ustb.efws.pipeline.domain.RiskLog;
import edu.ustb.efws.utils.SafeMath;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 短信发送处理
 *
 * @author TS Group
 */
class WarSmsHandler implements PipelineHandler {
    private final EfwsProperties properties;
    private final UserService userService;
    private final SmsService smsService;
    private final PositionService positionService;

    WarSmsHandler(EfwsProperties properties, UserService userService,
                  SmsService smsService, PositionService positionService) {

        this.properties = properties;
        this.userService = userService;
        this.smsService = smsService;
        this.positionService = positionService;
    }

    @Override
    @SuppressWarnings("unchecked")
    public Optional<Object> handle0(Object data) {
        List<RiskLog> logs = (List<RiskLog>) data;

        logs.stream()
                .filter(e -> e.getScore().intValue() >= properties.getSmsWarScore())
                .forEach(e -> WarSmsCache.INSTANCE.waring(e.getPositionId(), e.getScore()));

        return Optional.of(data);
    }
}
